package org.shoukaiseki.app.interceptor.service.impl;

import org.shoukaiseki.app.interceptor.constant.AppAccessInterceptorConstants;
import org.shoukaiseki.app.interceptor.service.IAppUserSessionService;
import org.shoukaiseki.common.utils.ServletUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
public class AppUserSessionServiceImpl implements IAppUserSessionService {

    @Override
    public void saveAppUserToSession(Object user) {
        HttpSession session = ServletUtils.getHttpSession();
        saveAppUserToSession(session,user);
    }

    @Override
    public void saveAppUserToSession(HttpSession session, Object user) {
        session.setAttribute(AppAccessInterceptorConstants.APP_USER_SESSION_ATTRNAM,user);
    }

    @Override
    public <T> T getAppUserFromSession() {
        HttpSession session = ServletUtils.getHttpSession();
        return getAppUserFromSession(session);
    }

    @Override
    public <T> T getAppUserFromSession(HttpSession session) {
        return (T)session.getAttribute(AppAccessInterceptorConstants.APP_USER_SESSION_ATTRNAM);
    }


}
